package com.fr.cell.clipboard;

import com.fr.util.Utils;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class ElementsTransferable
  implements Transferable, ClipboardOwner
{
  public static final DataFlavor CellElementsClipDataFlavor = createConstant(CellElementsClip.class, "CellElementsClip");
  public static final DataFlavor FloatElementClipDataFlavor = createConstant(FloatElementsClip.class, "FloatElementClip");
  public static final DataFlavor StringDataFlavor = createConstant(String.class, "String");
  private static final DataFlavor[] flavors = { CellElementsClipDataFlavor, FloatElementClipDataFlavor, StringDataFlavor };
  private List dataList = new ArrayList();

  private static DataFlavor createConstant(Class paramClass, String paramString)
  {
    try
    {
      return new DataFlavor(paramClass, paramString);
    }
    catch (Exception localException)
    {
    }
    return null;
  }

  public void addObject(Object paramObject)
  {
    this.dataList.add(paramObject);
  }

  public Object getFirstObject()
  {
    if (this.dataList.size() <= 0)
      return null;
    return this.dataList.get(0);
  }

  public DataFlavor[] getTransferDataFlavors()
  {
    return ((DataFlavor[])flavors.clone());
  }

  public boolean isDataFlavorSupported(DataFlavor paramDataFlavor)
  {
    for (int i = 0; i < flavors.length; ++i)
      if (paramDataFlavor.equals(flavors[i]))
        return true;
    return false;
  }

  public Object getTransferData(DataFlavor paramDataFlavor)
    throws UnsupportedFlavorException, IOException
  {
    if (paramDataFlavor == null)
      return null;
    for (int i = 0; i < this.dataList.size(); ++i)
    {
      Object localObject = this.dataList.get(i);
      if (localObject == null)
        break label55:
      if (Utils.classInstanceOf(paramDataFlavor.getRepresentationClass(), localObject.getClass()))
        return localObject;
    }
    label55: return null;
  }

  public void lostOwnership(Clipboard paramClipboard, Transferable paramTransferable)
  {
  }

  public static Object getElementNotStringTransderData(Transferable paramTransferable)
    throws UnsupportedFlavorException, IOException
  {
    for (int i = 0; i < flavors.length - 1; ++i)
    {
      Object localObject = paramTransferable.getTransferData(flavors[i]);
      if (localObject != null)
        return localObject;
    }
    return null;
  }
}